<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>欢迎页</title>
    <link rel="stylesheet" href="../../static/frame/layui/css/layui.css">
    <link rel="stylesheet" href="../../static/frame/static/css/style.css">
    <link rel="icon" href="../../static/frame/static/image/code.png">
</head>
<body class="body">
<div class="layui-row layui-col-space10 my-index-main">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">选择应用</label>
            <div class="layui-input-block">
                <select id="applist" name="applist" lay-search required lay-verify="required">
                </select>
            </div>
        </div>
        <div id="buybody">

        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>


<script src="../../static/jquery-3.3.1.js"></script>
<script type="text/javascript" src="../../static/frame/layui/layui.js"></script>
<script type="text/javascript" src="../../static/js/index.js"></script>
<script type="text/javascript" src="../../static/frame/echarts/echarts.min.js"></script>
<script>
    //Demo
    layui.use('form', function () {

        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            data.field.id = data.field.applist;
            var loading = layer.load();
            $.ajax({
                url: '../ajax.php?mod=buy_submit',
                type: 'POST',
                dataType: 'html',
                data: 'content=' + encodeURI(JSON.stringify(data.field)),
                success: function (data) {
                    layer.close(loading);
                    layer.alert(data);
                },
                error: function (data) {
                    layer.close(loading);
                    layer.msg('请求失败' + data);
                }
            })
            //layer.msg(JSON.stringify(data.field));
            return false;
        });

        form.on('select', function (data) {
            loadbuybody(data.value);
            return false;
        });
        var load = layer.load();
        $.ajax({
            url: '../ajax.php?mod=user_applist',
            type: 'POST',
            dataType: 'html',
            data: '',
            success: function (data) {
                layer.close(load);
                $('#applist').html(data);
                form.render('select');
                //layer.msg(data);

            },
            error: function (data) {
                layer.close(load);
                layer.msg('请求失败' + data);
            }
        })


    });

    function loadbuybody(appid) {
        var loading = layer.load();

        $.ajax({
            url: '../ajax.php?mod=loadbuybody',
            type: 'POST',
            dataType: 'html',
            data: 'appid=' + appid,
            success: function (data) {
                layer.close(loading);
                $("#buybody").html(data);
            },
            error: function (data) {
                layer.close(loading);
                layer.msg('请求失败' + data);
            }
        })
    }
</script>
</body>
</html>